using System;
namespace Dogfight2008
{
  public class CollisionRule
  {
    Handler handler;
    Type type1, type2;

    public delegate void Handler(object object1, object object2);

    public CollisionRule(Type type1, Type type2, Handler handler) {
      ThrowOnNull(type1, type2, handler);
      this.handler = handler;
      this.type1 = type1;
      this.type2 = type2;
    }

    public void ApplyTo(object object1, object object2)
    {
      ThrowOnNull(object1, object2);
      if (type1.IsInstanceOfType(object1) && type2.IsInstanceOfType(object2))
        handler(object1, object2);
    }

    void ThrowOnNull(params object[] objs)
    {
      foreach (object o in objs)
        if (o == null)
          throw new Exception();
    }
  }
}
